using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Mmht.DB
{
    public class AdminDB
    {
        public DataTable FindByName(string name)
        {
            DataTable dt = new DataTable();
            string sql = string.Empty;
            sql = "select name ,password,id from admin where name='" + name.ToString() + "'";
            operate op = new operate();
            dt = op.Query(sql);
            return dt;
        }
        public DataTable FindbyId(int id) 
        {
            DataTable dt = new DataTable();
            string sql = string.Empty;
            sql = "select * from admin where id="+id.ToString()+"";
            operate op = new operate();
            dt = op.Query(sql);
            return dt;
        }
        public bool InsertAdmin(string name,string password,int created_by,string e_mail,string tel) 
        {
            DateTime now = DateTime.Now;
            string sql = string.Empty;
            string remark = "administrater";
            sql = "insert into admin(name,password,created_at,created_by,e_mail,tel,remark)values('"+name.ToString()+"','"+password .ToString()+"','"+ now +"','"+created_by .ToString ()+"','"+e_mail .ToString ()+"','"+tel.ToString ()+"','"+ remark +"')";
            operate op = new operate();
            bool rst = op.Execute(sql);
            return rst;
        }
        public DataTable SelectAdmin() 
        {
            DataTable dt = new DataTable();
            string sql = string.Empty;
            sql = "select * from admin";
            operate op = new operate();
            dt = op.Query(sql);
            return dt;
        }
        public bool DelAdmin(int id) 
        {
            string sql = string.Empty;
            sql = "delete from admin where id="+ id.ToString()+ "";
            operate op=new operate ();
            bool rst = op.Execute(sql);
            return rst;
        }
        public bool UpdateAdmin1(string e_mail, string tel, int id)
        {
            string sql = string.Empty;
            sql = "update admin set e_mail='" + e_mail.ToString() + "',tel='" + tel.ToString() + "' where id=" + id.ToString() + "";
            operate op = new operate();
            bool rst = op.Execute(sql);
            return rst;
        }
        public bool UpdateAdmin2(string password,string e_mail,string tel,int id) 
        {
            string sql = string.Empty;
            sql = "update admin set password='"+password .ToString ()+"',e_mail='"+e_mail .ToString ()+"',tel='"+tel .ToString ()+"' where id="+id.ToString ()+"";
            operate op = new operate();
            bool rst = op.Execute(sql);
            return rst;
        }
    }
}
